public class LeetCode {
    public String longestCommonPrefix(String[] strs) {
        String ret = strs[0];
        for (int i = 1; i < strs.length; i++) {
            ret = findCommon(ret,strs[i]);
        }
        return ret;
    }
    public String findCommon(String ret,String str){
        int i = 0;
        while(i<Math.min(ret.length(),str.length()) && ret.charAt(i)==str.charAt(i)){
            i++;
        }
        return ret.substring(0,i);
    }
    public String longestCommonPrefix2(String[] strs) {
        for (int i = 0; i < strs[0].length(); i++) {
            char tmp = strs[0].charAt(i);
            for (int j = 1; j < strs.length; j++) {
                if(i==strs[j].length() || strs[j].charAt(i)!=tmp){
                    return strs[0].substring(0,i);
                }
            }
        }
        return strs[0];
    }
}
